const config = {
	httpUrl: "http://www.xuanyuanwuye.com:1504", 
	// httpUrl: "http://192.168.0.16:1504"

}

export class HTTP {
	request({url, data = {} }) { // http请求
		const promise = new Promise((resolve, reject)=>{
			uni.request({
				url: config.httpUrl + url,
				method: "POST",
				data: data,
				success: res => { 
					const code = res.data.code
					const data = res.data.data
					if(code == 1001) {
						resolve(data)
					} else {
						this._show_error(res.data.message)
					}
				},
				fail: err => {
					reject()
					this._show_error()
				}
			})
		})
		
		return promise
	}
	
	uploadFile({url,files,formData}) {
		return new Promise((resolve,reject) => {
			uni.uploadFile({
				url: config.httpUrl + url,
				files: files,
				formData: formData,
				success: (res) => {
					resolve(res)
				},
				fail: () => {
					this._show_error()
					reject()
				}
			})
		})
	}
	
	
	// 添加下划线方法，为私有方法
	_show_error(code) {
		uni.showToast({
			title: code || '抱歉，发生了一个错误',
			icon: "none"
		})
	}
}